<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
		<link rel="stylesheet" href="../../css/public.css" media="all">
		<script  href="../../js/http.js"></script>
		<style>
			body {
            background-color: #ffffff;
        }
    </style>
	</head>
	<body>
		<div class="layui-form layuimini-form">

			
			<div class="layui-form-item">
				<label class="layui-form-label required">端口名称</label>
				<div class="layui-input-block">
					<input type="text" name="mc" id="mc" value="" placeholder="某某名称" class="layui-input" lay-verify="required" lay-reqtext="端口名称不能为空">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label required">端口地址</label>
				<div class="layui-input-block ">
					<input type="text" name="ip" id="ip" placeholder="127.0.0.1" value="" class="layui-input" lay-verify="required"
					 lay-reqtext="端口地址不能为空">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label required">端口号</label>
				<div class="layui-input-block">
					<input type="number" name="port" id="port" placeholder="3306" value="" class="layui-input" lay-verify="required" lay-reqtext="端口号不能为空">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label required">监控状态</label>
				<div class="layui-input-block" >
					<input type="radio" name="ifsocket" value=0 title="启用监控"  checked="checked">
					<input type="radio" name="ifsocket" value=1 title="停止监控">
				</div>
			</div>


			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
				</div>
			</div>
		</div>
		</div>
	
		<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
		<script src="../../js/lay-config.js" charset="utf-8"></script>
		
		<script>
	
		
			layui.use(['form','table','http'], function() {
				var $ = layui.jquery,
					form = layui.form,
					table = layui.table,
			        http = layui.http;

				//监听提交
				form.on('submit(saveBtn)', function(data) {

                               console.log(data.field);
							    console.log(http.api);
					$.ajax({
						type: "post",
						async: false,
					    url: http.api + '/port/add',
						data: data.field,
						dataType: "json",
						success: function(response) {
							if (response.code == 0) {
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							//修改成功后刷新父界面
							window.parent.location.reload();
							} else {
								window.history.go(-1);
							}

						},
						error: function(e) {
							 console.log(data)
							alert("请求异常。");
						}
					});


				});

			});
			
			
		</script>
	</body>
</html>
